import { createApp } from 'vue'

import '@/styles/index.css' // tailwindcss 样式放最前面防止和ui框架样式冲突
import '@/styles/reset.css'
import 'element-plus/dist/index.css'
import '@/styles/global.css'
import '@/styles/globalVar.scss'

import App from './App.vue'
import { router } from './router/index'
import './router/permission'

import { createPinia } from 'pinia'
import piniaPluginPersist from 'pinia-plugin-persist'

import { ElMessage } from 'element-plus'
// 全局注册element plus图标组件
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import axios from 'axios'
import service from '@/api/axios'
import dayjs from 'dayjs'
import * as lodash from 'lodash'
// 使用vuelsp
import './vueLsp/index'

// 使用echarts
import VueECharts from 'vue-echarts'
import * as echarts from 'echarts'

// 自定义插件
import fullScreen from './plugins/fullScreen'

// svg
import './components/SvgIcon/index.js'
import SvgIcon from './components/SvgIcon/index.vue'
require('./mock')
const pinia = createPinia()
pinia.use(piniaPluginPersist)

// 解决resize表格出错问题
const debounce = (fn, delay) => {
    let timer = null
    return function () {
        const context = this
        const args = arguments
        clearTimeout(timer)
        timer = setTimeout(function () {
            fn.apply(context, args)
        }, delay)
    }
}
const _ResizeObserver = window.ResizeObserver
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
        callback = debounce(callback, 16)
        super(callback)
    }
}

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
} // svg组件
app.component('svg-icon', SvgIcon)
// 注册vue-echarts组件
app.component('v-chart', VueECharts)

app.config.globalProperties.$axios = axios
app.config.globalProperties.$serviceReq = service
app.config.globalProperties.$dayjs = dayjs
app.config.globalProperties.$lodash = lodash

app.config.globalProperties.$ElMessage = ElMessage

app.use(fullScreen)
app.use(VueECharts)
app.use(router)
app.use(pinia)
app.mount('#app')
